package com.zxn.drag.utils;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;

/**
 * Created by zxn on 2020/3/18.
 */
public class AnimUtils {

    public static AnimationSet createHideTranslate(Animation.AnimationListener listener) {
        TranslateAnimation mTranslateAnimation
                = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF,0f,
                Animation.RELATIVE_TO_SELF,0.0f,
                Animation.RELATIVE_TO_SELF,1.0f);
        AlphaAnimation mAlphaAnimation = new AlphaAnimation(1.0f, 0.5f);

        AnimationSet mAnimationSet = new AnimationSet(true);
        mAnimationSet.addAnimation(mTranslateAnimation);
        mAnimationSet.addAnimation(mAlphaAnimation);
        mAnimationSet.setDuration(1000);
        mAnimationSet.setFillAfter(true);
        mAnimationSet.setAnimationListener(listener);
        return mAnimationSet;
    }

    public static AnimationSet createFinishAnimation(Animation.AnimationListener listener) {
        ScaleAnimation mScaleAnimation = new ScaleAnimation(0.2f, 1.0f, 0.2f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        AlphaAnimation mAlphaAnimation = new AlphaAnimation(0.2f, 1.0f);
        AnimationSet mAnimationSet = new AnimationSet(true);
        mAnimationSet.addAnimation(mScaleAnimation);
        mAnimationSet.addAnimation(mAlphaAnimation);
        mAnimationSet.setDuration(600);
        mAnimationSet.setAnimationListener(listener);
        return mAnimationSet;
    }

    public static AnimationSet createHideAnimation(Animation.AnimationListener listener) {
        ScaleAnimation hideScaleAnim = new ScaleAnimation(1.0f, 1.0f, 1.0f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        AlphaAnimation hideAlphaAnim = new AlphaAnimation(1.0f, 0.9f);

        AnimationSet mHideAction = new AnimationSet(true);
        mHideAction.addAnimation(hideScaleAnim);
        mHideAction.addAnimation(hideAlphaAnim);
        mHideAction.setDuration(1000);
        mHideAction.setAnimationListener(listener);
        return mHideAction;
    }

    public static AnimationSet createShowAnimation() {
        AnimationSet mShowAction = new AnimationSet(true);
        ScaleAnimation showScaleAnim = new ScaleAnimation(0.8f, 1.0f, 0.8f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        AlphaAnimation showAlphaAnim = new AlphaAnimation(0.0f, 1.0f);
        mShowAction.addAnimation(showScaleAnim);
        mShowAction.addAnimation(showAlphaAnim);
        mShowAction.setDuration(150);
        return mShowAction;
    }

}
